package edu.cuit.avatar.inherit;

import java.util.Objects;

/**
 * @author <a href="mailto:1020zhaodan@163.com">Adan</a>
 * @version 1.0
 * @date 2025/7/9 15:35
 */
public class Circle extends Geometric{
    public static final float PI = 3.14f;

    private float radius;

    public Circle(float radius){
        //super(); //调用父类无参的构造方法
        this.radius = radius;
    }

    public Circle(float radius, String color, boolean filled){
        super(color, filled);//调用父类的对应的构造方法,只能出现在构造方法的第一条语句
        this.radius = radius;

    }

    public float getRadius() {
        return radius;
    }

    public void setRadius(float radius) {
        this.radius = radius;
    }

    /**
     * 计算圆的面积
     * @return 圆的面积
     */
    public float getArea(){
        return PI * radius * radius;
    }


    /**
     * JDK规定：如果两个对象相等,那么它们的hashcode值一定相等
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Circle circle = (Circle) o;
        return Float.compare(radius, circle.radius) == 0;
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(radius);
    }
}
